from django.db import models

from django.contrib.auth.models import User
from django.forms import ModelForm
from django.core.exceptions import ValidationError
from barrelhouse.core.vendors.models import vendor_account
from barrelhouse.core.domains.models import second_level_domain, third_level_domain

class ssl_certificate(models.Model):
    '''provides an object to track signed SSL certificates so they won't expire / processes can be automated'''

    name = models.CharField(max_length=512, unique=True, verbose_name="SSL Certificate", help_text="name for SSL Certificate")
    issue_date = models.DateTimeField(auto_now=False, help_text="date certificate begins to be valid")
    expire_date = models.DateTimeField(auto_now=False, verbose_name="Expire Date", help_text="last valid date for certificate")
    certificate_authority = models.ForeignKey(vendor_account, verbose_name="Certificate Authority", help_text = "associated contact for Certificate Authority")
    file_csr = models.FileField(upload_to="csr/%Y/%m/%d", verbose_name="CSR file", help_text="certificate CSR" )
    file_key = models.FileField(upload_to="key/%Y/%m/%d", verbose_name="Key file", help_text="certificate key file")
    file_crt = models.FileField(upload_to="crt/%Y/%m/%d", verbose_name="CRT file", help_text="copy of signed certificate from CA")
    notes = models.TextField(blank=True, help_text="notes associated with this domain")

    def __unicode__(self):
        return self.name

    def get_absolute_url(self):
        return "sslcerts/%i/" % self.id

    class Meta:
        verbose_name = "SSL Certificate"
